package com.dragon.manage.action;

import java.util.LinkedHashMap;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dragon.manage.bean.AmusementInfo;
import com.dragon.manage.bean.AmusementType;
import com.dragon.manage.bean.GameName;
import com.dragon.manage.bean.ManageUser;
import com.dragon.manage.bean.MatchInfo;
import com.dragon.manage.bean.OddsInfoTmp;
import com.dragon.manage.bean.TeamInfo;
import com.dragon.manage.service.IManageAmusementSerice;
import com.dragon.manage.service.IManageService;
import com.dragon.manage.util.LogUtil;
import com.dragon.manage.util.ManageUtil;
import com.dragon.manage.util.RightUtil;
import com.dragon.manage.util.StaticData;
import com.dragon.manage.util.StringUtil;
import com.dragon.manage.util.TimeUtil;
import com.opensymphony.xwork2.ActionContext;


/**
 * 比赛管理
 * @author 34225_000
 *
 */
@SuppressWarnings("rawtypes")
public class ManageAmusementAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private IManageService manageService;
	
	private IManageAmusementSerice manageAmusementService;
	

//	//權限ID
//	private static final int RightUtil.getRightId(this.getClass().getName()) = 12;

	/**
	 * 获取添加比赛的页面
	 * @return
	 */
	public String addAmusementPage(){
		/*
		 * 容器和返回的json值
		 */
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 再通过sessionid获取用户信息
			 */
			
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result,
					request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			String type =request.getParameter("gameType");
			if(type==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			
			//获取战队列表
			List<TeamInfo> teamList = manageAmusementService.getTeamList(Integer.parseInt(type));
			result.put(StaticData.reKey.teamList.getKey(), teamList);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		} catch (Exception e) {
			LogUtil.error("获取添加比赛的页面报错",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
	}
	
	/**
	 * 获取竞猜类型列表
	 * @return
	 */
	public String getAmusementTypeList(){
		/*
		 * 容器和返回的json值
		 */
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 再通过sessionid获取用户信息
			 */
			
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, request,manageService, 0);
			if(manageUser==null){
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			String matchId=request.getParameter("matchId");
			if(matchId==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			//获取竞猜类型
			List<AmusementType> amusementTypeList = manageAmusementService.getAmusementTypeList();
			MatchInfo matchInfo = manageAmusementService.getMatchInfoById(Integer.parseInt(matchId));
			if(matchInfo==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.Match_id_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			//获取主队信息
			TeamInfo hostTeam = manageAmusementService.getTeamInfoById(matchInfo.getHostTeam());
			//获取主队信息
			TeamInfo guestTeam = manageAmusementService.getTeamInfoById(matchInfo.getGuestTeam());
			//替换标识符
			StringUtil.replaceSign(amusementTypeList, hostTeam, guestTeam);
			
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
			result.put("amusementTypeList", amusementTypeList);
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		} catch (Exception e) {
			LogUtil.error("获取添加比赛的页面报错",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
	}
	
	/**
	 * 添加赛事
	 * @return
	 */
	public String addMatch(){
		/*
		 * 容器和返回的json值
		 */
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 再通过sessionid获取用户信息
			 */
			
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result,
					request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			//主队id
			String mTeamId=request.getParameter("mTeam");
			//客队id
			String uTeamId=request.getParameter("uTeam");
			//开始时间
			String startTime = request.getParameter("startTime");
			//封盘时间
			String endTime = request.getParameter("endTime");
			//游戏类型
			String gameType = request.getParameter("gameType");
			//标题
			String matchTitle=request.getParameter("matchTitle");
			//图片
			String matchImage=request.getParameter("matchImage");
			if(mTeamId==null||mTeamId.isEmpty()
					||uTeamId==null||uTeamId.isEmpty()
					||startTime==null||startTime.isEmpty()
					||endTime==null||endTime.isEmpty()
					||gameType==null||gameType.isEmpty()
					||matchTitle==null||matchTitle.isEmpty()
					||matchImage==null||matchImage.isEmpty()){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			/*
			 * 生成比赛信息
			 */
			MatchInfo matchInfo = new MatchInfo();
			matchInfo.setHostTeam(Integer.parseInt(mTeamId));
			matchInfo.setGuestTeam(Integer.parseInt(uTeamId));
			matchInfo.setStartDate(TimeUtil.parseDate(startTime));
			matchInfo.setEndDate(TimeUtil.parseDate(endTime));
			matchInfo.setGameType(Integer.parseInt(gameType));
			matchInfo.setMatchTitle(matchTitle);
			matchInfo.setMatchImage(matchImage);
			matchInfo.setMatchStatus(StaticData.AmusementStatus.putaway.getType());
			boolean b = manageAmusementService.createMatch(matchInfo);
			if(!b){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.createMatch_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			//获取竞猜类型
			List<AmusementType> amusementTypeList = manageAmusementService.getAmusementTypeList();
			//获取主队信息
			TeamInfo hostTeam = manageAmusementService.getTeamInfoById(matchInfo.getHostTeam());
			//获取主队信息
			TeamInfo guestTeam = manageAmusementService.getTeamInfoById(matchInfo.getGuestTeam());
			//替换标识符
			StringUtil.replaceSign(amusementTypeList, hostTeam, guestTeam);
			
			
			result.put("amusementTypeList", amusementTypeList);
			result.put("matchInfo", matchInfo);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		} catch (Exception e) {
			LogUtil.error("添加比赛的报错",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
	}
	/**
	 * 获取比赛列表
	 * @return
	 */
	public String getMatchList(){
		/*
		 * 容器和返回的json值
		 */
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 再通过sessionid获取用户信息
			 */
			
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			//游戏类型
			String type=request.getParameter("type");
			String page=request.getParameter("page");
			if(type==null||page==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			//获取对应类型下的比赛
			result = manageAmusementService.getMatchInfoListByType(Integer.parseInt(type),Integer.parseInt(page));
			//返回参数
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
		} catch (Exception e) {
			LogUtil.error("获取比赛列表",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
		return StaticData.RE_SUCCESS;
	}
	
	/**
	 * 获取单个比赛信息
	 * @return
	 */
	public String getMatchInfo(){
		/*
		 * 容器和返回的json值
		 */
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 再通过sessionid获取用户信息
			 */
			
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			String matchId=request.getParameter("matchId");
			if(matchId==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			MatchInfo matchInfo = manageAmusementService.getMatchInfoById(Integer.parseInt(matchId));
			if(matchInfo==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.Match_id_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
			result.put(StaticData.reKey.matchInfo.getKey(), matchInfo);
			ct.put(StaticData.reKey.result.getKey(), result);
		} catch (Exception e) {
			LogUtil.error("获取单个比赛信息",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
		return StaticData.RE_SUCCESS;
	}
	/**
	 * 更新比赛信息
	 * @return
	 */
	public String updateMatchInfo(){
		/*
		 * 容器和返回的json值
		 */
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 再通过sessionid获取用户信息
			 */
			
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			//参数
			String matchId=request.getParameter("matchId");
			//主队id
			String mTeamId=request.getParameter("mTeam");
			//客队id
			String uTeamId=request.getParameter("uTeam");
			//开始时间
			String startTime = request.getParameter("startTime");
			//封盘时间
			String endTime = request.getParameter("endTime");
			//游戏类型
			String gameType = request.getParameter("gameType");
			//游戏状态
			String matchStatus = request.getParameter("matchStatus");
			//主队分数
			String hostScore = request.getParameter("hostScore");
			//客队分数
			String guestScore = request.getParameter("guestScore");
			//标题
			String matchTitle=request.getParameter("matchTitle");
			//图片
			String matchImage=request.getParameter("matchImage");
			if(matchId==null||matchId.isEmpty()){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			/*
			 * 获取比赛信息
			 */
			MatchInfo matchInfo = manageAmusementService.getMatchInfoById(Integer.parseInt(matchId));
			if(matchInfo==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.Match_id_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			/*
			 * 更新比赛信息
			 */
			if(mTeamId!=null&&!mTeamId.isEmpty()){
				matchInfo.setHostTeam(Integer.parseInt(mTeamId));
			}
			if(matchStatus!=null&&!matchStatus.isEmpty()){
				matchInfo.setMatchStatus(Integer.parseInt(matchStatus));
			}
			if(uTeamId!=null&&!uTeamId.isEmpty()){
				matchInfo.setGuestTeam(Integer.parseInt(uTeamId));
			}
			if(startTime!=null&&!startTime.isEmpty()){
				matchInfo.setStartDate(TimeUtil.parseDate(startTime));
			}
			if(endTime!=null&&!endTime.isEmpty()){
				matchInfo.setEndDate(TimeUtil.parseDate(endTime));
			}
			if(gameType!=null&&!gameType.isEmpty()){
				matchInfo.setGameType(Integer.parseInt(gameType));
			}
			
			if(hostScore!=null&&!hostScore.isEmpty()){
				matchInfo.setHostScore(Integer.parseInt(hostScore));
			}
			if(guestScore!=null&&!guestScore.isEmpty()){
				matchInfo.setGuestScore(Integer.parseInt(guestScore));
			}
			if(matchTitle!=null&&!matchTitle.isEmpty()){
				matchInfo.setMatchTitle(matchTitle);
			}
			if(matchImage!=null&&!matchImage.isEmpty()){
				matchInfo.setMatchImage(matchImage);
			}
			/*
			 * 更新比赛信息
			 */
			result = manageAmusementService.updateMatchInfo(matchInfo,manageUser);
			ct.put(StaticData.reKey.result.getKey(), result);
		} catch (Exception e) {
			LogUtil.error("更新比赛信息",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
		return StaticData.RE_SUCCESS;
	}
	/**
	 * 添加竞猜项目
	 * @return
	 */
	public String addAmusementInfo(){
		/*
		 * 容器和返回的json值
		 */
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 获取用户
			 */
			
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			/*
			 * 获取参数
			 */
			String matchId=request.getParameter("matchId");
			String amusementTypes=request.getParameter("amusementType");
			String type=request.getParameter("type");
			String startTime=request.getParameter("startTime");
			String endTime=request.getParameter("endTime");
			String oddsType=request.getParameter("oddsType");
			if(matchId==null||matchId.isEmpty()
					||amusementTypes==null||amusementTypes.isEmpty()
					||type==null||type.isEmpty()
					||startTime==null||startTime.isEmpty()
					||endTime==null||endTime.isEmpty()
					||oddsType==null||oddsType.isEmpty()){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			AmusementType amusementType = manageAmusementService.getAmusementTypeById(Integer.parseInt(amusementTypes));
			if(amusementType==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			//获取的竞猜选项个数
			int count = Integer.parseInt(type);
			
			OddsInfoTmp tmp = null;
			LinkedHashMap<Integer,OddsInfoTmp> oddsInfoMap = new LinkedHashMap<Integer, OddsInfoTmp>();
			int oddsIdTmp = 0;
			String odds = "";
			TeamInfo teamInfo = null;
			for(int i=1;i<count+1;i++){
				oddsIdTmp = Integer.parseInt(request.getParameter("oddsId"+i));
				odds = request.getParameter("odds"+i);
				if(odds==null||odds.isEmpty()){
					result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
					ct.put(StaticData.reKey.result.getKey(), result);
					return StaticData.RE_SUCCESS;
				}
				if((amusementType.getType()==2||amusementType.getType()==3)){
					if(oddsIdTmp==StaticData.no_param){
						tmp = new OddsInfoTmp(oddsIdTmp+StaticData.first_split+
								"都没有"+StaticData.first_split+
								odds);
					}else{
						teamInfo = manageAmusementService.getTeamInfoById(oddsIdTmp);
						tmp = new OddsInfoTmp(teamInfo.getId()+StaticData.first_split+
								teamInfo.getTeamName()+StaticData.first_split+
								odds);
					}
					
				}else{
					tmp = new OddsInfoTmp(amusementType.getTypeOptionMap(oddsIdTmp).getOddsId()+StaticData.first_split+
							amusementType.getTypeOptionMap(oddsIdTmp).getOddsName()+StaticData.first_split+
							odds);
				}
				oddsInfoMap.put(tmp.getOddsId(),tmp);
			}
			/*
			 * 生成竞猜信息
			 */
			AmusementInfo amusementInfo = new AmusementInfo();
			amusementInfo.setMatchId(Integer.parseInt(matchId));
			amusementInfo.setAmusementType(amusementType.getId());
			amusementInfo.setOddsInfoMap(oddsInfoMap);
			amusementInfo.setCreateDate(TimeUtil.parseDate(startTime));
			amusementInfo.setEndDate(TimeUtil.parseDate(endTime));
			amusementInfo.setMatchStatus(StaticData.AmusementStatus.putaway.getType());
			amusementInfo.setOddsType(Integer.parseInt(oddsType));
			manageAmusementService.createAmusement(amusementInfo);
			/*
			 * 返回前端信息
			 */
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
		} catch (Exception e) {
			LogUtil.error("添加竞猜项目报错",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
		return StaticData.RE_SUCCESS;
	}
	
	/**
	 * 删除竞猜选项
	 * @return
	 */
	public String deleteAmusementInfo(){
		/*
		 * 容器和返回的json值
		 */
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 获取用户
			 */
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			/*
			 * 获取参数
			 */
			String amusementInfoId=request.getParameter("amusementInfoId");
			if(amusementInfoId==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			
			
			/*
			 * 返回前端信息
			 */
			result = manageAmusementService.deleteAmusementInfo(StringUtil.getParam(amusementInfoId));
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		} catch (Exception e) {
			LogUtil.error("获取竞猜信息",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
		
	}
	
	/**
	 * 删除竞猜选项
	 * @return
	 */
	public String deleteMatch(){
		/*
		 * 容器和返回的json值
		 */
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 获取用户
			 */
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			/*
			 * 获取参数
			 */
			String matchId=request.getParameter("matchId");
			if(matchId==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			
			
			/*
			 * 返回前端信息
			 */
			result = manageAmusementService.deleteMatch(StringUtil.getParam(matchId));
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		} catch (Exception e) {
			LogUtil.error("获取竞猜信息",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
		
	}
	/**
	 * 获取竞猜信息
	 * @return
	 */
	public String getAmusementInfo(){
		/*
		 * 容器和返回的json值
		 */
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 获取用户
			 */
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			/*
			 * 获取参数
			 */
			String amusementInfoId=request.getParameter("amusementInfoId");
			if(amusementInfoId==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			AmusementInfo amusementInfo = 
					manageAmusementService.getAmusementInfoById(Integer.parseInt(amusementInfoId));
			if(amusementInfo == null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			
			/*
			 * 返回前端信息
			 */
			result.put(StaticData.reKey.amusementInfo.getKey(), amusementInfo);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
		} catch (Exception e) {
			LogUtil.error("获取竞猜信息",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
		return StaticData.RE_SUCCESS;
	}
	
	/**
	 * 修改竞猜信息
	 * @return
	 */
	public String updateAmusementInfo(){
		/*
		 * 容器和返回的json值
		 */
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 获取用户
			 */
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			/*
			 * 获取参数
			 */
			//主键id
			String amusementInfoId=request.getParameter("amusementInfoId");
			//对应的比赛id
			String matchId=request.getParameter("matchId");
			//下注类型
			String amusementTypes=request.getParameter("amusementType");
			//开始时间
			String startTime=request.getParameter("startTime");
			//封盘时间
			String endTime=request.getParameter("endTime");
			//下注个数
			String type=request.getParameter("type");
			//状态
			String matchStatus=request.getParameter("matchStatus");
			//结果
			String amusementResult=request.getParameter("amusementResult");
			//封盘时间
			String oddsType=request.getParameter("oddsType");
			if(amusementInfoId==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			
			AmusementInfo amusementInfo = 
					manageAmusementService.getAmusementInfoById(Integer.parseInt(amusementInfoId));
			if(amusementInfo == null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			
			AmusementType amusementType = null;
			/*
			 * 是否要更新竞猜选项
			 */
			if(type!=null){
				amusementType = manageAmusementService.getAmusementTypeById(Integer.parseInt(amusementTypes));
				//获取的竞猜选项个数
				int count = Integer.parseInt(type);
				OddsInfoTmp tmp = null;
				LinkedHashMap<Integer,OddsInfoTmp> oddsInfoMap = new LinkedHashMap<Integer, OddsInfoTmp>();
				int oddsIdTmp = 0;
				TeamInfo teamInfo = null;
				for(int i=1;i<count+1;i++){
					oddsIdTmp = Integer.parseInt(request.getParameter("oddsId"+i));
					if((amusementType.getType()==2||amusementType.getType()==3)){
						if(oddsIdTmp==StaticData.no_param){
							tmp = new OddsInfoTmp(oddsIdTmp+StaticData.first_split+
									"都没有"+StaticData.first_split+
									request.getParameter("odds"+i));
						}else{
							teamInfo = manageAmusementService.getTeamInfoById(oddsIdTmp);
							tmp = new OddsInfoTmp(teamInfo.getId()+StaticData.first_split+
									teamInfo.getTeamName()+StaticData.first_split+
									request.getParameter("odds"+i));
						}
						
					}else{
						tmp = new OddsInfoTmp(amusementType.getTypeOptionMap(oddsIdTmp).getOddsId()+StaticData.first_split+
								amusementType.getTypeOptionMap(oddsIdTmp).getOddsName()+StaticData.first_split+
								request.getParameter("odds"+i));
					}

					oddsInfoMap.put(tmp.getOddsId(),tmp);
				}
				amusementInfo.setOddsInfoMap(oddsInfoMap);
			}
			/*
			 * 是否要更新对应的比赛
			 */
			if(matchId!=null){
				amusementInfo.setMatchId(Integer.parseInt(matchId));
			}
			/*
			 * 是否要更新赔率方式
			 */
			if(oddsType!=null){
				amusementInfo.setOddsType(Integer.parseInt(oddsType));
			}
			/*
			 * 下注的类型
			 */
			if(amusementType!=null){
				amusementInfo.setAmusementType(amusementType.getId());
			}
			/*
			 * 开盘时间
			 */
			if(startTime!=null){
				amusementInfo.setCreateDate(TimeUtil.parseDate(startTime));
			}
			/*
			 * 封盘的时间
			 */
			if(endTime!=null){
				amusementInfo.setEndDate(TimeUtil.parseDate(endTime));
			}
			/*
			 * 状态
			 */
			if(matchStatus!=null){
				amusementInfo.setMatchStatus(Integer.parseInt(matchStatus));
			}
			/*
			 * 结果
			 */
			if(amusementResult!=null){
				//如果是录入结果状态，则更新状态
				amusementInfo.setAmusementResult(Integer.parseInt(amusementResult));
				amusementInfo.setMatchStatus(StaticData.AmusementStatus.first_result_check.getType());
			}
			/*
			 * 更新结果
			 */
			manageAmusementService.updateAmusementInfo(amusementInfo);
			/*
			 * 返回前端信息
			 */
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
			result.put(StaticData.reKey.amusementInfo.getKey(),amusementInfo);
			ct.put(StaticData.reKey.result.getKey(), result);
		} catch (Exception e) {
			LogUtil.error("修改竞猜信息",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
		return StaticData.RE_SUCCESS;
	}
	
	/**
	 * 获取游戏竞猜列表
	 * @return
	 */
	public String getAmusementIntoList(){
		/*
		 * 容器和返回的json值
		 */
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 再通过sessionid获取用户信息
			 */
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			String matchId=request.getParameter("matchId");
			if(matchId==null||matchId.isEmpty()){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			//获取比赛信息
			MatchInfo matchInfo = manageAmusementService.getMatchInfoById(Integer.parseInt(matchId));
			if(matchInfo==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			//获取竞猜列表
			JSONArray  amusementInfoList = manageAmusementService.getAmusementInfoList(matchInfo.getId());
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
			result.put(StaticData.reKey.amusementInfoList.getKey(), amusementInfoList);
			ct.put(StaticData.reKey.result.getKey(), result);
		} catch (Exception e) {
			LogUtil.error("获取游戏竞猜列表",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
		return StaticData.RE_SUCCESS;
	}
	
	/**
	 * 获取游戏列表信息
	 * @return
	 */
	public String getGameNameList(){
		/*
		 * 容器和返回的json值
		 */
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 获取用户
			 */
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, request,manageService, 0);
			if(manageUser==null){
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			List<GameName> gameList = manageAmusementService.getGameNameList();
			/*
			 * 返回前端信息
			 */
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
			result.put(StaticData.reKey.gameList.getKey(), gameList);
			ct.put(StaticData.reKey.result.getKey(), result);
		} catch (Exception e) {
			LogUtil.error("获取游戏列表信息",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
		return StaticData.RE_SUCCESS;
	}
	
	public IManageService getManageService() {
		return manageService;
	}
	public void setManageService(IManageService manageService) {
		this.manageService = manageService;
	}
	
	public IManageAmusementSerice getManageAmusementService() {
		return manageAmusementService;
	}
	public void setManageAmusementService(
			IManageAmusementSerice manageAmusementService) {
		this.manageAmusementService = manageAmusementService;
	}
}
